#include <stdio.h>
extern long ggtIterative(long, long, long*);
long CggtIterative(long a, long b, long* r) {
	if (a==0) return b;
    while (b!=0) {
        long c = a;
        while (c>=b) {
            c = c-b;
        }
        a=b;
        b=c;
    }
    return a;
}
int test() {
	long i,j, k;
	long carr[100],arr[100];
	for (k=0; k<100; k++) {
		carr[k]=0;
		arr[k]=0;
	}
	for (i=0; i<100; i++) {
		for (j=0; j<100; j++) {
			printf("Calculating expected...\n");
			long expected = CggtIterative(i,j,carr);
			printf("Calculating result...\n");
			long result = ggtIterative(i,j,arr);
			if (result != expected) {
				printf("ERROR: ggt(%ld,%ld)=%ld expected but got %ld\n", i, j, expected, result);
				return 0;
			} else {
				//printf("OK: ggt(%ld,%ld)=%ld expected and got %ld\n", i, j, expected, result);
			}
		}
	}
	return 1;
}
RET(test()==1);
